package com.app.dialog;

import android.app.ProgressDialog;
import android.content.Context;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import lib.common.R;


// title应为content

public class DialogLoading_weixin extends ProgressDialog {

	private static DialogLoading_weixin progressdialog = null ;
	private Context mContext;
	private static int mTheme = R.style.Theme_HalfTranslucent;
	
	private static boolean bCanCancled = true;
	
	
	private DialogLoading_weixin(Context context, int theme) {
		super(context, theme);
		// TODO Auto-generated constructor stub
		mContext = context;
	}
	
	/*
	public static DemoProgressDialog getInstance( Context context){
		if( progressdialog == null){
			progressdialog = new DemoProgressDialog(context);
		}
		
		return progressdialog;
	}
	*/

	// 
	public static  void ShowTitleDialog(Context context, String title)
	{  
		
		///*
		createProgressDialog(context);
		Window window = progressdialog.getWindow();
		WindowManager.LayoutParams lp = window.getAttributes();  
		lp.dimAmount =0f;
		window.setAttributes(lp);  
		progressdialog.setContentView(R.layout.dialog_loading_weixin);
		TextView tv_progress_title=(TextView)window.findViewById(R.id.tv_progress_title);
		tv_progress_title.setVisibility(View.VISIBLE);
		if(title != null){
			tv_progress_title.setText(title);
		}
		//*/
		
	}
	
	public static  void Show(Context context, String title, boolean bCancle)
	{  
		bCanCancled = bCancle;
		
		///*
		createProgressDialog(context);
		Window window = progressdialog.getWindow();
		WindowManager.LayoutParams lp = window.getAttributes();  
		lp.dimAmount =0f;
		window.setAttributes(lp);  
		progressdialog.setCanceledOnTouchOutside(!bCancle);
		progressdialog.setContentView(R.layout.dialog_loading_weixin);
		TextView tv_progress_title=(TextView)window.findViewById(R.id.tv_progress_title);
		tv_progress_title.setVisibility(View.VISIBLE);
		if(title != null){
			tv_progress_title.setText(title);
		}
		//*/
		
	}
	
	

	public static void ShowNoTitleDialog(Context context)
	{
		createProgressDialog(context);
		Window window = progressdialog.getWindow();
		WindowManager.LayoutParams lp = window.getAttributes();  
		lp.dimAmount = 0;
		window.setAttributes(lp); 
		progressdialog.setContentView(R.layout.dialog_loading_weixin);
	}
	
	
	public static void DismissProgressDialog(){
		if( progressdialog != null){
			progressdialog.dismiss();
			progressdialog = null;
		}
		
	}
	
	public static void Dismiss(){
		if( progressdialog != null){
			progressdialog.dismiss();
			progressdialog = null;
		}
		
	}

	private static  void createProgressDialog(Context context)
	{
		if(progressdialog==null)
		{
			progressdialog = new DialogLoading_weixin(context, mTheme);
		}

		
		progressdialog.setIndeterminate(true);
	//	progressdialog.setCancelable(false);
		progressdialog.setCanceledOnTouchOutside(false);
		progressdialog.show();
	}

	
	
	@Override
	public void onBackPressed() {
		// TODO Auto-generated method stub
		
		if(bCanCancled )
		{
			super.onBackPressed();
			DismissProgressDialog();
		}
	
	}	

}
